//import java.io.FileInputStream;
//import java.io.FileOutputStream;
//import java.io.IOException;
//import java.util.Scanner;
//
//// Press Shift twice to open the Search Everywhere dialog and type `show whitespaces`,
//// then press Enter. You can now see whitespace characters in your code.
//public class Main {
//    public static void main(String[] args) throws IOException {
//        FileOutputStream fos=new FileOutputStream("d:\\data.dat");
//        Scanner sc=new Scanner(System.in);
//        String str=sc.nextLine();
//        while(!str.equals("end"))
//        {
//            fos.write(str.getBytes());
//            fos.write("\n".getBytes());
//            str=sc.nextLine();
//        }
//        fos.close();
//        FileInputStream fis=new FileInputStream("d:\\data.dat");
//        int ret;
//        while((ret=fis.read())!=-1)
//        {
//            System.out.print((char)ret);
//        }
//        fis.close();
//    }
//}

//import java.io.BufferedReader;
//import java.io.FileReader;
//import java.io.FileWriter;
//import java.io.IOException;
//import java.util.Scanner;
//
//public class Main {
//    public static void main(String[] args) throws IOException {
//        FileWriter fiw=new FileWriter("d:\\data.txt");
//        Scanner sc=new Scanner(System.in);
//        String str=sc.nextLine();
//        while(!str.equals("end"))
//        {
//            fiw.write(str);
//            fiw.write("\n");
//            str=sc.nextLine();
//        }
//        fiw.close();
//        FileReader fir=new FileReader("d:\\data.txt");
//        BufferedReader bfr=new BufferedReader(fir);
//        String ret;
//        while((ret=bfr.readLine())!=null)
//        {
//            System.out.println(ret);
//        }
//        bfr.close();
//        fir.close();
//    }
//}


import java.io.*;

//import java.io.File;
//import java.io.FileReader;
//import java.io.IOException;
//import java.util.Scanner;
//
//public class Main {
//    public static void main(String[] args) throws IOException {
//        File file=new File("d:\\test.txt");
//        Scanner sc=new Scanner(file);
//        String ret;
//        StringBuffer num=new StringBuffer();
//        StringBuffer al=new StringBuffer();
//        while(sc.hasNext())
//        {
//            ret=sc.nextLine();
//            for(int i=0;i<ret.length();i++)
//            {
//                if(ret.charAt(i)>='0' && ret.charAt(i)<='9')
//                    num.append(ret.charAt(i));
//                else
//                    al.append(ret.charAt(i));
//            }
//        }
//        System.out.println("数字信息："+num.toString());
//        System.out.println("字符信息："+al.toString());
//    }
//}
class Student implements Serializable {
    String id;
    String name;
    int age;
    String clzz;

    public Student(String id, String name, int age, String clzz) {
        this.id = id;
        this.name = name;
        this.age = age;
        this.clzz = clzz;
    }

    @Override
    public String toString() {
        return "Student{" +
                "id='" + id + '\'' +
                ", name='" + name + '\'' +
                ", age=" + age +
                ", clzz=" + clzz +
                '}';
    }
}
public class Main {
    public static void main(String[] args) throws IOException,ClassNotFoundException{
        Student[] stu=new Student[3];
        Student s1=new Student("1","zhang",18,"1");
        Student s2=new Student("2","ng",18,"2");
        stu[0]=s1;
        stu[1]=s2;
        ObjectOutputStream objectOutputStream=new ObjectOutputStream(new FileOutputStream("stu.dat"));
        objectOutputStream.writeObject(stu);
        objectOutputStream.close();
        ObjectInputStream objectInputStream=new ObjectInputStream(new FileInputStream("stu.dat"));
        Object ret=objectInputStream.readObject();
        if(ret instanceof Student[])
        {
            Student[] r=(Student[]) ret;
            for(Student tmp:r)
            {
                System.out.println(tmp);
            }
        }
        objectInputStream.close();
    }
}